﻿from django.db import models
from mptt.models import MPTTModel
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify
from django.forms import ModelForm, Textarea
from slughifi import *


class Location(MPTTModel):
    #LOCATION_CHOICES=(('U','Uczelnia'),('S','Szkola'),('P','Przedszkole'),('O','Osiedle'),('M','Miasto'))
    lat = models.FloatField()
    lng = models.FloatField()
    name = models.CharField(max_length=200)
    slug = models.SlugField()
    #type = models.CharField(max_length=1, choices=LOCATION_CHOICES)
    address = models.CharField(max_length=200)	
    parent = models.ForeignKey('self',null=True, blank=True, related_name='children')
    def __unicode__(self):
        return self.name
        
    # def save(self):
        # self.slug = slugify(self.name)
        # super(Location, self).save()
		
        
class Announcement(models.Model):
    text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    votes = models.IntegerField()
    location = models.ForeignKey(Location)
    user = models.ForeignKey(User)
    #logo = models.ImageField(upload_to='logos')
        
    class Meta:
        ordering = ['-pub_date']
        
    def __unicode__(self):
        return self.text   		        

class AnnouncementForm(ModelForm):       
    class Meta:
        model = Announcement
        #fields = ('text', 'location')
        exclude = ('pub_date','votes','user')
        widgets = {
            'text': Textarea(attrs={'cols': 80, 'rows': 10}),
        }
    

		